<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>available_friends_for_trip (TripsController)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File trips_controller.rb, line 204</span>
        <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">available_friends_for_trip</span>(<span class="ruby-identifier">trip</span>)
                <span class="ruby-identifier">friends</span> = <span class="ruby-constant">Friendship</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>,<span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> {<span class="ruby-identifier">:user_a_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">current_user</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>})
                <span class="ruby-identifier">friends_invited</span> = <span class="ruby-constant">UserTrip</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> {<span class="ruby-identifier">:trip_id</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">trip</span>})
                <span class="ruby-identifier">friends_uninvited</span> = []
                
                <span class="ruby-identifier">friends</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">friend</span><span class="ruby-operator">|</span>
                        <span class="ruby-identifier">is_invited</span> = <span class="ruby-keyword kw">false</span>           
                        <span class="ruby-identifier">friends_invited</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">friend_invited</span><span class="ruby-operator">|</span>
                                <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">friend</span>.<span class="ruby-identifier">user_b_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">friend_invited</span>.<span class="ruby-identifier">user_id</span>
                                        <span class="ruby-identifier">is_invited</span> = <span class="ruby-keyword kw">true</span>
                                <span class="ruby-keyword kw">end</span>
                        <span class="ruby-keyword kw">end</span>
                        <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">is_invited</span>
                                <span class="ruby-identifier">user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">friend</span>.<span class="ruby-identifier">user_b_id</span>)
                                <span class="ruby-identifier">friends_uninvited</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">user</span>
                        <span class="ruby-keyword kw">end</span> 
                <span class="ruby-keyword kw">end</span>           
                <span class="ruby-identifier">friends_uninvited</span>
        <span class="ruby-keyword kw">end</span></pre>
</body>
</html>